package com.tul.exercise.base.jmockit.jmockitprogramconstructure;

import com.tul.exercise.base.jmockit.base.HelloJMockit;
import mockit.Expectations;
import mockit.Mocked;
import mockit.Verifications;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertTrue;

/**
 *  《JMockit中文网》示例 2
 *
 *  JMockit的程序结构
 */
public class ProgramConstructureTest {
    @Mocked
    HelloJMockit helloJMockit;

    @Test
    public void test1() {

        String str = "hello,david";
        // 录制(Record)
        new Expectations() {{
           helloJMockit.sayHello();
           result = str;
        }};

        // 重放(Replay)
        String msg = helloJMockit.sayHello();
        assertTrue(msg.equals(str));

        // 验证(Verification
        new Verifications(){{
           helloJMockit.sayHello();
           times = 1;
        }};
    }

    @Test
    public void test2(@Mocked HelloJMockit helloJMockit /* 这是一个测试参数 */) {
        String str = "hello,david";
        // 录制(Record)
        new Expectations() {{
            helloJMockit.sayHello();
            result = str;
        }};

        // 重放(Replay)
        String msg = helloJMockit.sayHello();
        assertTrue(msg.equals(str));

        // 验证(Verification
        new Verifications(){{
            helloJMockit.sayHello();
            times = 1;
        }};

    }
}
